Skip to content

JYP / 4월 2주차 / 2문제#19

Merged
Mingguriguri merged 2 commits intoAlgorithmStudy-Allumbus:mainfrom
JYP0824:main
Apr 15, 2024
Merged

JYP / 4월 2주차 / 2문제#19
Mingguriguri merged 2 commits intoAlgorithmStudy-Allumbus:mainfrom
JYP0824:main

Conversation

@JYP0824
Copy link
Contributor

@JYP0824 JYP0824 commented Apr 14, 2024

목표 문제 - 2 문제 (풀이 1문제)

queuestack 문제 풀이

  • 스택은 LIFO 형태를 갖고 있기에 따로 처리할 부분이 없어 스택 부분은 무시하고 여러개의 큐를 하나의 큐로 생각해 풀어나가면 되는 문제이다
  • 문제의 입력으로 0(큐) / 1(스택)으로 받으나 스택 부분을 무시하고 큐만을 사용하여 원하는 결과를 얻을 수 있다
from collections import deque
import sys
input = sys.stdin.readline

a = int(input())
sec1 = list(map(int, input().split()))  # 0 or 1
sec2 = list(map(int, input().split()))

b = int(input())
sec3 = list(map(int, input().split()))

queue = deque([])

# for문에서 스택 부분 무시하도록 함
for i in range(a):
  if sec1[i] == 0:
    queue.appendleft(sec2[i])
else:  
  if queue == []:
    print(*sec3)
    sys.exit()


for j in range(b):
  queue.append(sec3[i])
  print(queue.popleft(), end = " ")

Copy link
Collaborator

@Mingguriguri Mingguriguri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생했습니다.
코드 넣을 때 ```<- 옆에 python이라고 치면 파이썬 IDE 형식으로 코드 나와요!! 참고해유~

Copy link
Collaborator

@zaqquum zaqquum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다b

@Mingguriguri Mingguriguri merged commit d5b7ee8 into AlgorithmStudy-Allumbus:main Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants